package com.sh.service.impl;

import java.math.BigDecimal;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.sh.dao.CustomerDao;
import com.sh.dao.RptDao;
import com.sh.entity.Customer;
import com.sh.entity.MonthBalanceRPT;
import com.sh.entity.ReceivePayRPT;
import com.sh.entity.User;
import com.sh.service.RptService;
import com.sh.util.DateUtil;
import com.sh.util.StrUtil;

@Service()
public class RptServiceImpl implements RptService{
	@Autowired
	private RptDao rptDao;
	//客户 的信息
	@Autowired
	private CustomerDao customerDao;

	/**
	 * 查询 应收报表
	 * 运输费1 = 应收金额 + 其他金额 -回扣   客户名对应的数据
	 * 运输费2 = 金额+其他费用-回扣 	车主对应的数据
	 *
	 * 修理费1 = 客户对应的金额
	 * 修理费2 = 车主对应的金额
	 *
	 * 轮胎费1 = 客户对应的金额
	 * 轮胎费2 = 车主对应的金额
	 *
	 * 油费、修理费、轮胎费 = 金额汇总
	 * 客户为J的时候
	 * 期初 + 运输费1 + 油费+修理费2+轮胎费2-手动输入- 运输费2-修理费1-轮胎费1
	 * 客户为D的时候
	 * 期初 + 运输费2+ 修理费1+轮胎费1-运输费1-油费-修理费2-轮胎费2-手动输入
	 *
	 * 应收报表，只计算 客户为J的数据
	 * @throws ParseException
	 * */
	@Override
	public List<ReceivePayRPT> listReceiveRPT(Map<String, Object> conMap, User user, String sysTime) throws ParseException {
		// TODO Auto-generated method stub
		List<ReceivePayRPT> rtnList = new ArrayList<ReceivePayRPT>();


		String customerName =
				(String)conMap.get("customerName");
		customerName = StrUtil.filterNull(customerName);

		//开始日期
		String startDate =
				(String)conMap.get("startDate");

		//结束日期
		String endDate =
				(String)conMap.get("endDate");


		List<Customer> customerList = null;
		if(!"".equals(customerName)){
			//如果 有客户的 查询条件
			ArrayList<String> nameList = new ArrayList<String>();
			nameList.add(customerName);
			customerList = customerDao.listCustomerByNames(nameList);

		}else{
			//如果 没有客户 条件的话
			//先查询 出 当前条件下的 所有的 客户名称customerName
			//查询所有客户信息
			customerList =
					customerDao.listCustomer(new HashMap<String,Object>());

		}


		if(customerList!=null &&
				customerList.size()>0){

			for(Customer customer:customerList){
				if("J".equals(customer.getType())){

					ReceivePayRPT model = publicPRTFunc(customer, startDate, endDate);
					rtnList.add(model);
				}

			}

		}

		return rtnList;
	}


	/**
	 * 查询 应付报表
	 * 运输费1 = 应收金额 + 其他金额 -回扣   客户名对应的数据
	 * 运输费2 = 金额+其他费用-回扣 	车主对应的数据
	 *
	 * 修理费1 = 客户对应的金额
	 * 修理费2 = 车主对应的金额
	 *
	 * 轮胎费1 = 客户对应的金额
	 * 轮胎费2 = 车主对应的金额
	 *
	 * 油费、修理费、轮胎费 = 金额汇总
	 * 客户为J的时候
	 * 期初 + 运输费1 + 油费+修理费2+轮胎费2-手动输入- 运输费2-修理费1-轮胎费1
	 * 客户为D的时候
	 * 期初 + 运输费2+ 修理费1+轮胎费1-运输费1-油费-修理费2-轮胎费2-手动输入
	 *
	 * 应付报表，只计算 客户为D的数据
	 *
	 * @throws ParseException
	 * */
	@Override
	public List<ReceivePayRPT> listPayRPT(Map<String, Object> conMap, User user, String sysTime) throws ParseException {
		// TODO Auto-generated method stub
		List<ReceivePayRPT> rtnList = new ArrayList<ReceivePayRPT>();


		String customerName =
				(String)conMap.get("customerName");
		customerName = StrUtil.filterNull(customerName);

		//开始日期
		String startDate =
				(String)conMap.get("startDate");

		//结束日期
		String endDate =
				(String)conMap.get("endDate");


		List<Customer> customerList = null;
		if(!"".equals(customerName)){
			//如果 有客户的 查询条件
			ArrayList<String> nameList = new ArrayList<String>();
			nameList.add(customerName);
			customerList = customerDao.listCustomerByNames(nameList);

		}else{
			//如果 没有客户 条件的话
			//先查询 出 当前条件下的 所有的 客户名称customerName
			//查询所有客户信息
			customerList =
					customerDao.listCustomer(new HashMap<String,Object>());

		}


		if(customerList!=null &&
				customerList.size()>0){

			for(Customer customer:customerList){
				if("D".equals(customer.getType())){
					ReceivePayRPT model =
							publicPRTFunc(customer, startDate, endDate);
					rtnList.add(model);

				}

			}

		}

		return rtnList;
	}


	//查询 月度余额报表
	@Override
	public List<MonthBalanceRPT> listMonthlyBalanceRPT(Map<String, Object> conMap, User user, String sysTime) {
		// TODO Auto-generated method stub

		return rptDao.listMonthlyBalacenRPT(conMap);
	}





	/**
	 * 计算   月份余额 (默认为所有客户 计算上个月的 月度余额)
	 * 客户最开始的余额 是最新的余额或者是 客户的初始金额
	 * @throws Exception
	 *
	 * */
	@Override
	public String calculateBalance(User user, String sysTime) throws Exception {
		// TODO Auto-generated method stub


		//拿取上个月时间(格式"yyyy-mm")
		String preMonth = DateUtil.getPreMonth(null);

		String msg =
				calculateCustomBalance(preMonth,preMonth,user,sysTime);

		return msg;
	}
	/**
	 * 计算   查询时间段 内  所有月份余额
	 * 客户最开始的余额 是最新的余额或者是 客户的初始金额
	 * @param user 客户
	 * @param startMonth 开始计算月份
	 * @param endMonth   结束计算月份
	 * @throws Exception
	 *
	 * */
	public synchronized String calculateCustomBalance(
			String startMonth,
			String endMonth,
			User user,
			String sysTime
	) throws Exception {
		// TODO Auto-generated method stub

		//先查询 出 当前条件下的 所有的 客户名称customerName
		//查询所有客户信息
		List<Customer> customerList  =
				customerDao.listCustomer(new HashMap<String,Object>());


		List<ReceivePayRPT> rtnList = new ArrayList<ReceivePayRPT>();

		if(customerList!=null &&
				customerList.size()>0){
			String startDay = "";
			String endDay = "";
			String startMonthTmp = "";
			for(Customer customer:customerList){
				startMonthTmp = startMonth;
				//从开始月份 到结束月份的数据全部 计算一遍
				do{
					//拿取当前月份的 最后一天
					String curMonthLastDay =
							DateUtil.getCurMonthLastDay(startMonthTmp);
					startDay = startMonthTmp + "-01";
					endDay = startMonthTmp + "-" + curMonthLastDay;

					//计算 当前客户 当前月的 各个金额
					ReceivePayRPT rptModel =
							publicPRTFunc(customer,startDay,endDay);
					rtnList.add(rptModel);

					startMonthTmp = DateUtil.addMonth(startMonthTmp);

				}while(startMonthTmp.equals(endMonth));

			}
			//将 计算好的数据 修改到 月度余额 表
			//如果 没有数据就插入，如果已经存在就修改
			rptDao.updateMonthlyBalance(rtnList,user,sysTime);
		}

		return "";
	}




	//结转
	@Override
	public String carryForward(String carryYear, User user, String sysTime) {
		// TODO Auto-generated method stub
		rptDao.carryForward(carryYear,user,sysTime);
		return "";
	}





	//判断当前年份是不是已经结转
	@Override
	public String checkDataCarry(List<String> yearList) {
		// TODO Auto-generated method stub
		//查询所有结转年份
		List<String> rtnList = new ArrayList<>();
		List list = rptDao.selectCarryYearList();
		if(list!=null &&
				list.size()>0){
			for(int i=0;i<list.size();i++){
				Map map = (Map)list.get(i);
				String year = (String)map.get("info");
				rtnList.add(year);
			}

		}

		StringBuffer sb = new StringBuffer();
		sb.append("");
		for(String checkYear:yearList){
			//如果包含，表示已经结转，不能修改
			if(rtnList.contains(checkYear)){
				sb.append(checkYear + "、");
			}
		}
		String rtnStr = sb.toString();
		if(!"".equals(rtnStr)){
			return rtnStr + " 对应的年份已经结转";
		}

		return "";
	}


	/**
	 * 计算 报表的主要逻辑 方法
	 * @param customer 客户
	 * @param startDay 开始日期
	 * @param endDay 结束日期
	 * @throws ParseException
	 *
	 * */
	private ReceivePayRPT publicPRTFunc(
			Customer customer,
			String startDay,String endDay) throws ParseException{



		//1、根据客户名称 查询出  客户月度余额
		String balance =
				getMonthBalance(customer,startDay);

		//2、计算出 月初到 startDay之间的数据 作为 总的余额
		//也就是 startDay=每个月第一天  endDay = 当前的startDay
		String nowDayMonth = DateUtil.getNowDayMonth(startDay);
		String firstDay = nowDayMonth + "-01";//当月第一天
		ReceivePayRPT model =
				calculateReceivePayRPT(balance,customer,firstDay,startDay);

		//3、用 之前计算出来的balance 作为余额
		ReceivePayRPT rtnModel =
				calculateReceivePayRPT(model.getBalance(),customer,startDay,endDay);

		return rtnModel;
	}

	/**
	 * 拿取客户 月度余额
	 * 1、拿取 查询日期的上一个月份
	 * 2、根据上一个月份和客户名称 在月度金额表中拿取 当前客户上一个月的 余额；
	 * 	如果没有 找到上一个月就会去寻找最近的报表余额，如果有没有找到，就拿取客户的
	 * 	期初金额。
	 * @param customer 客户
	 * @param startDay 开始日期
	 *
	 * */
	private String getMonthBalance(Customer customer,String startDay) throws ParseException{
		//1、拿取 startDay 对应的上一个月份
		String nowMonth =
				DateUtil.getPreMonth(startDay);


		//2、查询  月度余额  表中 最新的余额数据 作为  余额
		Map<String,Object> conMap = new HashMap<String,Object>();
		conMap.put("customerName",customer.getCustomerName());
		conMap.put("nowMonth",nowMonth);
		String balance =
				rptDao.getBalanceByCustomerName(conMap);
		if(balance==null||"".equals(balance)){
			//如果 没有在 月度余额 表中查询到 余额，就找对应客户的初始金额
			balance = customer.getInitAmount();
		}


		return balance;
	}
	/**
	 * 计算 固定时间内的 用户的报表信息
	 * @param balance  月度余额
	 * @param customer 客户
	 * @param startDay 开始日期
	 * @param endDay 结束日期
	 *
	 * */
	private ReceivePayRPT calculateReceivePayRPT(String balance,
												 Customer customer,String startDay,String endDay) throws ParseException{

		ReceivePayRPT rtpModel = new ReceivePayRPT();
		//设置期初金额,就是上月余额
		rtpModel.setInitAmount(balance);

		//设置客户名称
		rtpModel.setCustomerName(customer.getCustomerName());

		//2、查询 当前客户的所有金额
		Map<String, Object> conMap = new HashMap<String,Object>();
		conMap.put("customerName", customer.getCustomerName());
		conMap.put("startDate", startDay);
		conMap.put("endDate", endDay);

		/**
		 * 运输费1 = 应收金额 + 其他金额 -回扣   客户名对应的数据
		 * 运输费2 = 金额+其他费用-回扣 	车主对应的数据
		 *
		 * 修理费1 = 客户对应的金额
		 * 修理费2 = 车主对应的金额
		 *
		 * 轮胎费1 = 客户对应的金额
		 * 轮胎费2 = 车主对应的金额
		 * */
		List list =  rptDao.listReceiveOrPayRPT(conMap);
		if(list!=null&&
				list.size()>0){

			Map map = (Map)list.get(0);

			double transport1Amount = 0.00;
			double transport2Amount = 0.00;
			double oilAmount = 0.00;
			double tires1Amount = 0.00;
			double tires2Amount = 0.00;
			double repair1Amount = 0.00;
			double repair2Amount = 0.00;
			double inputAmount = 0.00;
			if(map!=null){


				transport1Amount =
						map.get("transport1_amount")==null?0.00:(double)map.get("transport1_amount");
				transport2Amount =
						map.get("transport2_amount")==null?0.00:(double)map.get("transport2_amount");
				oilAmount =
						map.get("oil_amount")==null?0.00:(double)map.get("oil_amount");

				tires1Amount =
						map.get("tires1_amount")==null?0.00:(double)map.get("tires1_amount");
				tires2Amount =
						map.get("tires2_amount")==null?0.00:(double)map.get("tires2_amount");
				repair1Amount =
						map.get("repair1_amount")==null?0.00:(double)map.get("repair1_amount");
				repair2Amount =
						map.get("repair2_amount")==null?0.00:(double)map.get("repair2_amount");
				inputAmount =
						map.get("input_amount")==null?0.00:(double)map.get("input_amount");
			}
			//借方金额
			String JFAmount = "0";
			//贷方金额
			String DFAmount = "0";


			if("J".equals(customer.getType())){
				//如果是客户为 J 的用户

				//为J的时候 借方 金额  = 运输费1 + 油费+修理费2+轮胎费2
				JFAmount = new BigDecimal(transport1Amount)
						.add( new BigDecimal(tires2Amount))
						.add( new BigDecimal(repair2Amount))
						.add( new BigDecimal(oilAmount)).setScale(2, BigDecimal.ROUND_HALF_UP)+"";
				// 贷方金额 = 手动输入+ 运输费2+修理费1+轮胎费1
				DFAmount = new BigDecimal(transport2Amount)
						.add( new BigDecimal(tires1Amount))
						.add( new BigDecimal(repair1Amount))
						.add( new BigDecimal(inputAmount)).setScale(2, BigDecimal.ROUND_HALF_UP)+"";

			}else{

				//为D 的时候
				//借方金额 = 运输费2 +修理费1+轮胎费1
				JFAmount = new BigDecimal(transport2Amount)
						.add( new BigDecimal(tires1Amount))
						.add( new BigDecimal(repair1Amount)).setScale(2, BigDecimal.ROUND_HALF_UP)+"";

				//贷方金额 = 运输费1+油费+修理费2+轮胎费2+手动输入
				DFAmount = new BigDecimal(transport1Amount)
						.add( new BigDecimal(tires2Amount))
						.add( new BigDecimal(repair2Amount))
						.add( new BigDecimal(oilAmount))
						.add(new BigDecimal(inputAmount)).setScale(2, BigDecimal.ROUND_HALF_UP)+"";

			}
			//余额 = 期初+借方金额-贷方金额
			String blanceAmount = new BigDecimal(Float.parseFloat(balance))
					.add( new BigDecimal(Float.parseFloat(JFAmount)))
					.subtract( new BigDecimal(Float.parseFloat(DFAmount))).setScale(2, BigDecimal.ROUND_HALF_UP)+"";

//-----------------------设置 借方、贷方、余额
			rtpModel.setJfAmount(JFAmount);
			rtpModel.setDfAmount(DFAmount);
			rtpModel.setBalance(blanceAmount);

			//设置 运输费1（客户对应运输金额）
			rtpModel.setCustomerTransportFee(transport1Amount+"");
			//设置 运输费2（车主对应运输金额）
			rtpModel.setCarOwnerTransportFee(transport2Amount+"");
			//设置 修理费1（客户对应修理金额）
			rtpModel.setCustomerRepairFee(repair1Amount+"");
			//设置 修理费2（车主对应修理金额）
			rtpModel.setCarOwnerRepairFee(repair2Amount+"");
			//设置 轮胎费1（客户对应轮胎金额）
			rtpModel.setCustomerTiresFee(tires1Amount+"");
			//设置 轮胎费2（车主对应轮胎金额）
			rtpModel.setCarOwnerTiresFee(tires2Amount+"");
			//设置 手动补充输入
			rtpModel.setSupplyFee(inputAmount+"");
			//设置油费
			rtpModel.setOilFee(oilAmount+"");

			//4、拿取 startDay 对应的月份
			String nowMonth =
					DateUtil.getNowDayMonth(startDay);
			rtpModel.setMonth(nowMonth);

		}

		return rtpModel;
	}
	/**
	 *
	 * 拿取当前用户的 期初金额
	 * @throws ParseException
	 * @throws NumberFormatException
	 * */
	@Deprecated
	private String getInitBlance(String startDateCon, String customerType, String blance,Map queryBlanceConMap) throws NumberFormatException, ParseException {
		// TODO Auto-generated method stub

		String preMonthBlance = "0";


		//判断当前日期 是不是 当月第一天
		if(DateUtil.isFirstDay(startDateCon)){
			//如果是第一天，直接拿取上一个 月的 余额
			preMonthBlance = blance;

		}else{
			//如果不是 第一天

			List list =  rptDao.listReceiveOrPayRPT(queryBlanceConMap);

			//如果是 J 的客户
			if("J".equals(customerType)){
				if(list!=null&&list.get(0)!=null){
					for(int i=0;i<list.size();i++){
						Map map = (Map)list.get(i);
						double transport1Amount = 0.00;
						double transport2Amount = 0.00;
						double oilAmount = 0.00;
						double tires1Amount = 0.00;
						double tires2Amount = 0.00;
						double repair1Amount = 0.00;
						double repair2Amount = 0.00;
						double inputAmount = 0.00;

						if(map!=null){
							transport1Amount =
									map.get("transport1_amount")==null?0.00:(double)map.get("transport1_amount");
							transport2Amount =
									map.get("transport2_amount")==null?0.00:(double)map.get("transport2_amount");
							oilAmount =
									map.get("oil_amount")==null?0.00:(double)map.get("oil_amount");

							tires1Amount =
									map.get("tires1_amount")==null?0.00:(double)map.get("tires1_amount");
							tires2Amount =
									map.get("tires2_amount")==null?0.00:(double)map.get("tires2_amount");

							repair1Amount =
									map.get("repair1_amount")==null?0.00:(double)map.get("repair1_amount");
							repair2Amount =
									map.get("repair2_amount")==null?0.00:(double)map.get("repair2_amount");
							inputAmount =
									map.get("input_amount")==null?0.00:(double)map.get("input_amount");
						}

						//当前 用户都是性质为J的
						//为J的时候 期初 + 运输费1 + 油费+修理费2+轮胎费2-手动输入- 运输费2-修理费1-轮胎费1
						preMonthBlance = new BigDecimal(Float.parseFloat(blance))
								.add( new BigDecimal(transport1Amount))
								.add( new BigDecimal(tires2Amount))
								.add( new BigDecimal(repair2Amount))
								.add( new BigDecimal(oilAmount))
								.subtract(new BigDecimal(transport2Amount))
								.subtract(new BigDecimal(repair1Amount))
								.subtract(new BigDecimal(tires1Amount))
								.subtract(new BigDecimal(inputAmount)).setScale(2, BigDecimal.ROUND_HALF_UP)+"";


					}
				}else{
					preMonthBlance = blance;
				}
			}else{
				//如果是 D 的客户
				if(list!=null&&list.get(0)!=null){
					for(int i=0;i<list.size();i++){
						Map map = (Map)list.get(i);

						double transport1Amount = 0.00;
						double transport2Amount = 0.00;
						double oilAmount = 0.00;
						double tires1Amount = 0.00;
						double tires2Amount = 0.00;
						double repair1Amount = 0.00;
						double repair2Amount = 0.00;
						double inputAmount = 0.00;
						if(map!=null){
							transport1Amount =
									map.get("transport1_amount")==null?0.00:(double)map.get("transport1_amount");
							transport2Amount =
									map.get("transport2_amount")==null?0.00:(double)map.get("transport2_amount");
							oilAmount =
									map.get("oil_amount")==null?0.00:(double)map.get("oil_amount");

							tires1Amount =
									map.get("tires1_amount")==null?0.00:(double)map.get("tires1_amount");
							tires2Amount =
									map.get("tires2_amount")==null?0.00:(double)map.get("tires2_amount");

							repair1Amount =
									map.get("repair1_amount")==null?0.00:(double)map.get("repair1_amount");
							repair2Amount =
									map.get("repair2_amount")==null?0.00:(double)map.get("repair2_amount");
							inputAmount =
									map.get("input_amount")==null?0.00:(double)map.get("input_amount");

						}


						//为D 的时候 期初 + 运输费2+修理费1+轮胎费1 -运输费1-油费-修理费2-轮胎费2-手动输入
						preMonthBlance = new BigDecimal(Float.parseFloat(blance))
								.add( new BigDecimal(transport2Amount))
								.add( new BigDecimal(tires1Amount))
								.add( new BigDecimal(repair1Amount))
								.subtract( new BigDecimal(repair2Amount))
								.subtract( new BigDecimal(tires2Amount))
								.subtract( new BigDecimal(oilAmount))
								.subtract(new BigDecimal(transport1Amount))
								.subtract(new BigDecimal(inputAmount)).setScale(2, BigDecimal.ROUND_HALF_UP)+"";


					}
				}else{
					preMonthBlance = blance;
				}

			}



		}

		return preMonthBlance;
	}


	/**
	 * 测试所有方法
	 *
	 * */
	@Override
	public void testFunc(Map<String, Object> conMap) {
		// TODO Auto-generated method stub

		//测试 publicPRTFunc
		String customerName = (String)conMap.get("customerName");
		Customer c = new Customer();
		c.setCustomerName(customerName);
		c.setType("J");
		c.setInitAmount("5000");
		try {
			publicPRTFunc(c,"2020-04","");
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}
	/**
	 * 查询 应收报表
	 * 运输费1 = 应收金额 + 其他金额 -回扣   客户名对应的数据
	 * 运输费2 = 金额+其他费用-回扣 	车主对应的数据
	 *
	 * 修理费1 = 客户对应的金额
	 * 修理费2 = 车主对应的金额
	 *
	 * 轮胎费1 = 客户对应的金额
	 * 轮胎费2 = 车主对应的金额
	 *
	 * 油费、修理费、轮胎费 = 金额汇总
	 * 客户为J的时候
	 * 期初 + 运输费1 + 油费+修理费2+轮胎费2-手动输入- 运输费2-修理费1-轮胎费1
	 * 客户为D的时候
	 * 期初 + 运输费2+ 修理费1+轮胎费1-运输费1-油费-修理费2-轮胎费2-手动输入
	 *
	 *
	 * 应收报表，只计算 客户为J的数据
	 * @throws ParseException
	 * */
	@Deprecated
	public List<ReceivePayRPT> listReceiveRPT_Bat(Map<String, Object> conMap, User user, String sysTime) throws ParseException {
		// TODO Auto-generated method stub
		List<ReceivePayRPT> rtnList = new ArrayList<ReceivePayRPT>();


		String customerNameCon =
				(String)conMap.get("customerName");
		customerNameCon = StrUtil.filterNull(customerNameCon);

		//开始日期
		String startDateCon =
				(String)conMap.get("startDate");

		//拿取 开始日期 的 对应月份 的第一天 作为 开始日期
		String curMonthFirstDay =
				DateUtil.getCurMonthFirstDay(startDateCon);
		//拿取 开始日期 的 前一天 作为结束日期
		String preDay = DateUtil.getPreDay(startDateCon);
		//查询 上月 余额的时候  需要的条件
		Map<String,Object> queryBlanceConMap = new HashMap<String,Object>();
		queryBlanceConMap.put("startDate",curMonthFirstDay);
		queryBlanceConMap.put("endDate", preDay);


		List<Customer> customerList = null;
		if(!"".equals(customerNameCon)){
			//如果 有客户的 查询条件
			ArrayList<String> nameList = new ArrayList<String>();
			nameList.add(customerNameCon);
			customerList = customerDao.listCustomerByNames(nameList);

		}else{
			//如果 没有客户 条件的话
			//先查询 出 当前条件下的 所有的 客户名称customerName
			//查询所有客户信息
			customerList =
					customerDao.listCustomer(new HashMap<String,Object>());

		}


		if(customerList.size()>0){


			//删减数据，应收报表 只计算 性质为J的客户
			Iterator<Customer> sListIterator = customerList.iterator();
			while (sListIterator.hasNext()) {
				Customer c = sListIterator.next();
				if ("D".equals(c.getType())) {
					sListIterator.remove();
				}
			}
			//如果 删选数据以后 ，没有值了，直接返回
			if(customerList==null||customerList.size()==0){
				return rtnList;
			}

			for(Customer customer:customerList){
				ReceivePayRPT receiveRpt = new ReceivePayRPT();
//--------------------------设置客户名
				receiveRpt.setCustomerName(customer.getCustomerName());
				queryBlanceConMap.put("customerName", customer.getCustomerName());
				conMap.put("customerName", customer.getCustomerName());

				//客户性质
				String customerType = customer.getType();


				//拿取 开始日期的 上一个月 yyyy-MM
				String preMonth =
						DateUtil.getPreMonth(startDateCon);
				queryBlanceConMap.put("preMonth", preMonth);
				String blance =rptDao.getPreMonthBlance(queryBlanceConMap);

				//查询每个客户的期初金额
				/**
				 * 期初金额 = 上个月的期初金额+这个月到 查询这天之前一天的 余额
				 * */
				String preMonthBlance =
						getInitBlance(startDateCon,customerType,blance,queryBlanceConMap);
				//设置期初
				receiveRpt.setInitAmount(preMonthBlance);


				//拿取  当前 客户 的 所有金额信息
				List list =  rptDao.listReceiveOrPayRPT(conMap);
				for(int i=0;i<list.size();i++){
					Map map = (Map)list.get(i);

					double transport1Amount = 0.00;
					double transport2Amount = 0.00;
					double oilAmount = 0.00;
					double tires1Amount = 0.00;
					double tires2Amount = 0.00;
					double repair1Amount = 0.00;
					double repair2Amount = 0.00;
					double inputAmount = 0.00;
					if(map!=null){


						transport1Amount =
								map.get("transport1_amount")==null?0.00:(double)map.get("transport1_amount");
						transport2Amount =
								map.get("transport2_amount")==null?0.00:(double)map.get("transport2_amount");
						oilAmount =
								map.get("oil_amount")==null?0.00:(double)map.get("oil_amount");

						tires1Amount =
								map.get("tires1_amount")==null?0.00:(double)map.get("tires1_amount");
						tires2Amount =
								map.get("tires2_amount")==null?0.00:(double)map.get("tires2_amount");
						repair1Amount =
								map.get("repair1_amount")==null?0.00:(double)map.get("repair1_amount");
						repair2Amount =
								map.get("repair2_amount")==null?0.00:(double)map.get("repair2_amount");
						inputAmount =
								map.get("input_amount")==null?0.00:(double)map.get("input_amount");
					}




					//为J的时候 借方 金额  = 运输费1 + 油费+修理费2+轮胎费2
					String JFAmount = new BigDecimal(transport1Amount)
							.add( new BigDecimal(tires2Amount))
							.add( new BigDecimal(repair2Amount))
							.add( new BigDecimal(oilAmount)).setScale(2, BigDecimal.ROUND_HALF_UP)+"";
					// 贷方金额 = 手动输入+ 运输费2+修理费1+轮胎费1
					String DFAmount = new BigDecimal(transport2Amount)
							.add( new BigDecimal(tires1Amount))
							.add( new BigDecimal(repair1Amount))
							.add( new BigDecimal(inputAmount)).setScale(2, BigDecimal.ROUND_HALF_UP)+"";

					//余额 = 期初+借方金额-贷方金额
					String blanceAmount = new BigDecimal(Float.parseFloat(preMonthBlance))
							.add( new BigDecimal(Float.parseFloat(JFAmount)))
							.subtract( new BigDecimal(Float.parseFloat(DFAmount))).setScale(2, BigDecimal.ROUND_HALF_UP)+"";

//-----------------------设置 借方、贷方、余额
					receiveRpt.setJfAmount(JFAmount);
					receiveRpt.setDfAmount(DFAmount);
					receiveRpt.setBalance(blanceAmount);

				}
				rtnList.add(receiveRpt);
			}

		}

		return rtnList;
	}
	/**
	 * 查询 应付报表
	 * 运输费1 = 应收金额 + 其他金额 -回扣   客户名对应的数据
	 * 运输费2 = 金额+其他费用-回扣 	车主对应的数据
	 *
	 * 修理费1 = 客户对应的金额
	 * 修理费2 = 车主对应的金额
	 *
	 * 轮胎费1 = 客户对应的金额
	 * 轮胎费2 = 车主对应的金额
	 *
	 * 油费、修理费、轮胎费 = 金额汇总
	 * 客户为J的时候
	 * 期初 + 运输费1 + 油费+修理费2+轮胎费2-手动输入- 运输费2-修理费1-轮胎费1
	 * 客户为D的时候
	 * 期初 + 运输费2+ 修理费1+轮胎费1-运输费1-油费-修理费2-轮胎费2-手动输入
	 *
	 * 应付报表，只计算 客户为D的数据
	 *
	 * @throws ParseException
	 * */
	@Deprecated
	public List<ReceivePayRPT> listPayRPT_Bat(Map<String, Object> conMap, User user, String sysTime) throws ParseException {
		// TODO Auto-generated method stub
		List<ReceivePayRPT> rtnList = new ArrayList<ReceivePayRPT>();


		String customerNameCon =
				(String)conMap.get("customerName");
		customerNameCon = StrUtil.filterNull(customerNameCon);

		//开始日期
		String startDateCon =
				(String)conMap.get("startDate");

		//拿取 开始日期 的 对应月份 的第一天 作为 开始日期
		String curMonthFirstDay =
				DateUtil.getCurMonthFirstDay(startDateCon);
		//拿取 开始日期 的 前一天 作为结束日期
		String preDay = DateUtil.getPreDay(startDateCon);
		//查询 上月 余额的时候  需要的条件
		Map<String,Object> queryBlanceConMap = new HashMap<String,Object>();
		queryBlanceConMap.put("startDate",curMonthFirstDay);
		queryBlanceConMap.put("endDate", preDay);



		List<Customer> customerList = null;
		if(!"".equals(customerNameCon)){
			//如果 有客户的 查询条件
			ArrayList<String> nameList = new ArrayList<String>();
			nameList.add(customerNameCon);
			customerList = customerDao.listCustomerByNames(nameList);

		}else{
			//如果 没有客户 条件的话
			//先查询 出 当前条件下的 所有的 客户名称customerName
			//查询所有客户信息
			customerList =
					customerDao.listCustomer(new HashMap<String,Object>());

		}


		if(customerList.size()>0){


			//删减数据，应付报表 只计算 性质为D的客户
			Iterator<Customer> sListIterator = customerList.iterator();
			while (sListIterator.hasNext()) {
				Customer c = sListIterator.next();
				if ("J".equals(c.getType())) {
					sListIterator.remove();
				}
			}
			//如果 删选数据以后 ，没有值了，直接返回
			if(customerList==null||customerList.size()==0){
				return rtnList;
			}

			for(Customer customer:customerList){
				ReceivePayRPT receiveRpt = new ReceivePayRPT();
//--------------------------设置客户名
				receiveRpt.setCustomerName(customer.getCustomerName());
				queryBlanceConMap.put("customerName", customer.getCustomerName());
				conMap.put("customerName", customer.getCustomerName());

				//客户性质
				String customerType = customer.getType();


				//拿取 开始日期的 上一个月 yyyy-MM
				String preMonth =
						DateUtil.getPreMonth(startDateCon);
				queryBlanceConMap.put("preMonth", preMonth);
				String blance =rptDao.getPreMonthBlance(queryBlanceConMap);

				//查询每个客户的期初金额
				/**
				 * 期初金额 = 上个月的期初金额+这个月到 查询这天之前一天的 余额
				 * */
				String preMonthBlance =
						getInitBlance(startDateCon,customerType,blance,queryBlanceConMap);
				//设置期初
				receiveRpt.setInitAmount(preMonthBlance);


				//拿取  当前 客户 的 所有金额信息
				List list =  rptDao.listReceiveOrPayRPT(conMap);
				for(int i=0;i<list.size();i++){
					Map map = (Map)list.get(i);

					double transport1Amount = 0.00;
					double transport2Amount = 0.00;
					double oilAmount = 0.00;
					double tires1Amount = 0.00;
					double tires2Amount = 0.00;
					double repair1Amount = 0.00;
					double repair2Amount = 0.00;
					double inputAmount = 0.00;

					if(map!=null){
						transport1Amount =
								map.get("transport1_amount")==null?0.00:(double)map.get("transport1_amount");
						transport2Amount =
								map.get("transport2_amount")==null?0.00:(double)map.get("transport2_amount");
						oilAmount =
								map.get("oil_amount")==null?0.00:(double)map.get("oil_amount");

						tires1Amount =
								map.get("tires1_amount")==null?0.00:(double)map.get("tires1_amount");
						tires2Amount =
								map.get("tires2_amount")==null?0.00:(double)map.get("tires2_amount");
						repair1Amount =
								map.get("repair1_amount")==null?0.00:(double)map.get("repair1_amount");
						repair2Amount =
								map.get("repair2_amount")==null?0.00:(double)map.get("repair2_amount");
						inputAmount =
								map.get("input_amount")==null?0.00:(double)map.get("input_amount");
					}




					//为D 的时候
					//借方金额 = 运输费2 +修理费1+轮胎费1
					String JFAmount = new BigDecimal(transport2Amount)
							.add( new BigDecimal(tires1Amount))
							.add( new BigDecimal(repair1Amount)).setScale(2, BigDecimal.ROUND_HALF_UP)+"";

					//贷方金额 = 运输费1+油费+修理费2+轮胎费2+手动输入
					String DFAmount = new BigDecimal(transport1Amount)
							.add( new BigDecimal(tires2Amount))
							.add( new BigDecimal(repair2Amount))
							.add( new BigDecimal(oilAmount))
							.add(new BigDecimal(inputAmount)).setScale(2, BigDecimal.ROUND_HALF_UP)+"";
					//余额 = 期初+借方金额-贷方金额
					String blanceAmount = new BigDecimal(preMonthBlance)
							.add( new BigDecimal(JFAmount))
							.subtract( new BigDecimal(DFAmount)).setScale(2, BigDecimal.ROUND_HALF_UP)+"";

//-----------------------设置 借方、贷方、余额
					receiveRpt.setJfAmount(JFAmount);
					receiveRpt.setDfAmount(DFAmount);
					receiveRpt.setBalance(blanceAmount);





				}
				rtnList.add(receiveRpt);
			}

		}

		return rtnList;
	}
}
